package com.vids.utils;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonFilter;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.vids.constant.GlobalConstant;
import lombok.Data;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;

public class RestTemplateUtils {

    public static HttpHeaders setRequestHeader(String serverId) {
	// 设置远程调用的请求头
	HttpHeaders header = new HttpHeaders();
	header.setContentType(MediaType.APPLICATION_JSON_UTF8);
	header.add(GlobalConstant.USER_IDENTIFY, serverId);
	return header;
    }

    public static HttpHeaders setRequestHeader() {
	// 设置远程调用的请求头
	HttpHeaders header = new HttpHeaders();
	header.setContentType(MediaType.APPLICATION_JSON_UTF8);
	return header;
    }

    public static HttpHeaders setAuthHeader(String authHeader) {
	// 设置远程调用的请求头
	HttpHeaders header = new HttpHeaders();
	header.setContentType(MediaType.APPLICATION_JSON_UTF8);

	header.add("Authorization", authHeader);
	return header;
    }

    public static HttpEntity<String> HttpPost(String serverId, Object obj) throws JsonProcessingException {
	HttpHeaders header = setRequestHeader(serverId);
	ObjectMapper mapper = QueryUtils.getObjectMapperInstance("", new String[] {}, "com.vids.model",
		JsonFilter.class);
	HttpEntity<String> httpEntity = new HttpEntity<String>(mapper.writeValueAsString(obj), header);
	return httpEntity;
    }

	public static String getAuthHeader(){
		StringBuilder responseHeader = new StringBuilder();
		responseHeader.append("Digest realm=\"www.pciviid.com\"");
		responseHeader.append(",qop=\"auth\"");
		responseHeader.append(",algorithm=\"MD5\"");
		responseHeader.append(",nonce=\"" + UUID.randomUUID() + "\"");
		responseHeader.append(",opaque=\"" + UUID.randomUUID() + "\"");
		return responseHeader.toString();
	}


//	@Data
//	@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY, getterVisibility = JsonAutoDetect.Visibility.NONE)
//	public class ResponseStatusRequestObject {
//
//		private ResponseStatusRequestObject.ResponseStatus ResponseStatusObject;
//
//		@Data
//		@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY,
//			getterVisibility = JsonAutoDetect.Visibility.NONE)
//
//
//		public static class ResponseStatus {
//			private String Id;
//			private String LocalTime;
//			private String RequestURL;
//			private String StatusCode;
//			private String StatusString;
//		}
//	}


}
